<style scoped>

</style>

<template>
    <div class="see-inquiry-sheet-page seeDisabled">
        <el-form :inline="true" :model="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <!--询价单号-->
            <el-form-item :label="nowLangue.inquiryNo" class="selectMB10" >
                <el-input size="mini" disabled v-model="formInline.requestForQuotationId" placeholder=""></el-input>
            </el-form-item>
            <!--询价日期-->
            <el-form-item :label="nowLangue.inquiryDate" class="selectMB10" >
                <el-input size="mini" disabled v-model="formInline.createTime" placeholder=""></el-input>
            </el-form-item>
            <!--询价人员-->
            <el-form-item :label="nowLangue.inquiryPersonnel" class="selectMB10" >
                <el-input size="mini" disabled v-model="formInline.creatorName" placeholder=""></el-input>
            </el-form-item>
            <!--法人名称-->
            <el-form-item :label="nowLangue.legalName" class="selectMB10" >
                <el-select size="mini" disabled v-model="formInline.legalPersonName">
                    <el-option v-for="(legalPerson,index) in legalPersonDropDown" :key="index" :label="legalPerson.legalPersonName" :value="legalPerson.legalPersonName"></el-option>
                </el-select>
            </el-form-item>
            <!--询价类型-->
            <el-form-item :label="nowLangue.inquiryType" class="selectMB10" >
                <el-select size="mini" disabled v-model="formInline.typeName" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(inquiryType,index) in selectDropdown.type" :key="index" :label="inquiryType.label" :value="inquiryType.value"></el-option>
                </el-select>
            </el-form-item>
            <!--询价币别-->
            <el-form-item :label="nowLangue.inquiryCurrency" class="selectMB10" >
                <el-select size="mini" disabled v-model="formInline.currencyCode" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(inquiryCurrency,index) in selectDropdown.currencyCode" :key="index" :label="inquiryCurrency.label" :value="inquiryCurrency.value"></el-option>
                </el-select>
            </el-form-item>
            <!--金额是否含税-->
            <el-form-item :label="nowLangue.isTax" class="selectMB10" >
                <el-select size="mini" disabled v-model="formInline.isTaxName" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(isIncludeTax,index) in selectDropdown.isTax" :key="index" :label="isIncludeTax.label" :value="isIncludeTax.value"></el-option>
                </el-select>
            </el-form-item>
            <!--询价开始日期-->
            <el-form-item :label="nowLangue.inquiryStartDate"class="selectMB10" >
                <el-date-picker type="date" size="mini" :editable="false" disabled v-model="formInline.startTime" :placeholder="nowLangue.pleaseSelect"></el-date-picker>
            </el-form-item>
            <!--询价结束日期-->
            <el-form-item :label="nowLangue.inquiryEndDate" class="selectMB10" >
                <el-date-picker type="date" size="mini" :editable="false" disabled v-model="formInline.endTime" :placeholder="nowLangue.pleaseSelect"></el-date-picker>
            </el-form-item>
            <el-form-item class="selectMB10">
                <!--审核-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="formInline.inquiryStatus == 1" @click="handleReview" v-text="nowLangue.toExamine"></el-button>
                <!--审核-->
                 <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="formInline.inquiryStatus == 2" disabled @click="handleReview" v-text="nowLangue.toExamine"></el-button>
            </el-form-item>
            <el-form-item class="selectMB10">
                <!--审批-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="formInline.inquiryStatus == 2"  @click="handleApprove" v-text="nowLangue.approval"></el-button>
                <!--审批-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="formInline.inquiryStatus == 3" disabled  @click="handleApprove" v-text="nowLangue.approval"></el-button>
            </el-form-item>
            
        </el-form>
        <!--待询价明细表格     待询价明细：-->
        <label class="default-label" v-text="nowLangue.inquiryDetails"></label>
        <!-- 
        <el-button disabled class="bolder outsideBtnBS" size="mini" type="danger">导入</el-button>
        <el-button disabled class="bolder outsideBtnBS" size="mini" type="danger">新增</el-button>
        -->
        <el-table :data="inquiryDetailsData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence" width="40"></el-table-column>
            <!--备件编码-->
            <el-table-column prop="spareCoding" :label="nowLangue.spareCode" header-align="center" show-overflow-tooltip></el-table-column>
            <!--备件名称-->
            <el-table-column prop="spareName" :label="nowLangue.spareName" header-align="center" show-overflow-tooltip></el-table-column>
            <!--计量单位-->
            <el-table-column prop="measurementUnit" :label="nowLangue.materialUnit" header-align="center" width="120" show-overflow-tooltip></el-table-column>
            <!--询价数量-->
            <el-table-column prop="inquiryQty" :label="nowLangue.inquiryQty" header-align="center" width="120"></el-table-column>
            <!--币别-->
            <el-table-column prop="currencyCodeWord" :label="nowLangue.currencyCode" header-align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="moq" label="MOQ" header-align="center" width="180"></el-table-column>
            <!--交货周期(天)-->
            <el-table-column prop="deliveryCycle" :label="nowLangue.deliveryCycle" header-align="center"></el-table-column>

        </el-table>
        <!-- 待报价供应商明细    待报价供应商明细：-->
        <label class="default-label" v-text="nowLangue.listOfSuppliersToBeQuoted"></label>
        <!-- 
        <el-button disabled class="bolder outsideBtnBS" size="mini" type="danger" @click="addSupplier(supplierType)">新增</el-button>
        -->
        <el-table :data="supplierDetails" border style="width: 60%;" v-loading.body="loading" element-loading-text="拼命加载中">
           <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence" width="40"></el-table-column>
            <!--供应商编码-->
            <el-table-column prop="vendorCode" property="vendorCode" :label="nowLangue.supplierCode" header-align="center" show-overflow-tooltip></el-table-column>
            <!--供应商名称-->
            <el-table-column prop="vendor" property="vendor" :label="nowLangue.supplierName" header-align="center" show-overflow-tooltip></el-table-column>
        </el-table>
        <!-- 点击审核 审核弹窗 审核提示信息-->
        <el-dialog :title="nowLangue.auditPromptMsg" :visible.sync="handleReviewVisible" size="small" :lock-scroll="false">
            <el-form :model="reviewForm">
                <!--是否审核通过当前单据？-->
                <h2 v-text="nowLangue.auditTip"></h2>
                <!--审核意见-->
                <el-form-item :label="nowLangue.auditOpinion" >
                    <el-input type="textarea"  :rows="3" :placeholder="nowLangue.pleaseImport+nowLangue.auditOpinion" v-model="reviewForm.textarea">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--审核通过-->
                <el-button type="primary" @click="toExamine(1)" v-text="nowLangue.audited"></el-button>
                <!--审核不通过-->
                <el-button @click="toExamine(0)" v-text="nowLangue.auditNotThrough"></el-button>
            </div>
        </el-dialog>
        
        <!-- 点击审批 审批弹窗 -->
        <!--审批提示信息-->
        <el-dialog id="approvalMask" :title="nowLangue.approvalPromptMsg" :visible.sync="handleApprovalVisible" size="small" :lock-scroll="false">
            <el-form :model="approvalForm">
                <!--是否审批通过当前单据？-->
                <h2 v-text="nowLangue.approvalTip"></h2>
                <!--审批意见-->
                <el-form-item :label="nowLangue.approvalOpinions" >
                    <el-input type="textarea"  :rows="3" :placeholder="nowLangue.pleaseImport+nowLangue.approvalOpinions" v-model="approvalForm.textarea">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--审批通过-->
                <el-button type="primary" @click="examinationAndApproval(1)" v-text="nowLangue.approvaled"></el-button>
                <!--审批不通过-->
                <el-button @click="examinationAndApproval(0) " v-text="nowLangue.approvalNotThrough"></el-button>
            </div>
        </el-dialog>
        
    </div>
</template>


<script>

    export default {
        data() {
            return {
                nowLangue:{},
                // 查询表单
                formInline:{
                    id:"",
                    requestForQuotationId:"",
                    createTime:"",
                    creatorId:"",
                    legalPersonId:"",
                    type:"",
                    currencyCode:"",
                    isTax:"",
                    startTime:"",
                    endTime:"",

                    legalPersonNameList:[]

                    // supplierName:"",
                    // inquiryType:"",
                    // inquiryStatus:"请选择"
                },
                legalPersonDropDown:[],
                loading:false,
                inquiryDetailsData: [],// 待询价明细表格
                supplierDetails:[],// 待报价供应商明细
                selectDropdown:[],  // 下拉列表的值
                spareData:[],
                
                handleReviewVisible:false,    //审核弹窗
                reviewForm:{      //审核内容
                    textarea:""
                },
                handleApprovalVisible:false,    // 审批弹窗
                approvalForm:{      //审批内容
                    textarea:""
                },

                providerList:[],//新增供应商弹框中，选中的供应商的信息
                spareList:[], //新增备件弹框中，选中的备件的信息
                supplierType:1

            };
        },
        created:function(){
            var _this=this;
            _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
        },
        computed:{
            // powerData(){
            //     return this.$store.state.powerData;
            // },
            languageType(){
                return this.$store.state.languageType;
            }
        },
        watch:{
            languageType(){
                var _this=this;
                _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
            }
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'SeeInquirySheet');

            _this.createInquerySheetDropdownValue();
            _this.legalPersonDropDownValue();

            _this.formInline.requestForQuotationId=_this.$route.query.requestForQuotationId;
            
            _this.seeInquiry();  //进入页面直接 查看询价单列表


        },
        methods: {
            legalPersonDropDownValue(){  //法人名称下拉列表值
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"legalPerson/ofCurrentUser",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.legalPersonDropDown = data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },


           seeInquiry(){   //查看询价单列表
                var _this =this;
                var tmp = {requestForQuotationId:_this.formInline.requestForQuotationId};
                $.ajax({
                    url:_this.procurement_service+'inquirySheet/see',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        // console.log(data);
                        if(data.success){
                            _this.formInline=data.data[0];
                            _this.formInline.inquiryStatus=data.data[0].inquiryStatus;
                            // console.log(_this.formInline);
                            _this.inquiryDetailsData=data.data[0].inquiryDetailsList;
                            _this.supplierDetails= data.data[0].supplierDetailsList;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
           },

            createInquerySheetDropdownValue(){ //下拉列表的值
                var _this =this;
                var tmp = ["type","isTax","currencyCode"];
                $.ajax({
                    type:'POST',
                    url:_this.procurement_service+'metadata/getPullDownList',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:"application/json;charset=utf-8",
                    success: function(data){
                        if(data.success){
                            _this.selectDropdown=data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                });
            },
            // 获取当前时间
            getTime(){
                var myDate=new Date();
                var year=myDate.getFullYear();
                var month=myDate.getMonth()+1;
                var day=myDate.getDate();
                var hours=myDate.getHours();
                var minutes=myDate.getMinutes();
                var seconds=myDate.getSeconds();
                var time = year +"-"+ month +"-"+ day +" "+ hours +":"+ minutes +":"+ seconds;
                return time;
            },
            //审核按钮
            handleReview(){
                var _this=this;
                _this.handleReviewVisible=true;
            },
            toExamine(auditorStatus){   //1 审核通过  0审核不通过
                var _this = this;
                var auditorTime=_this.getTime();
                var tmp = {requestForQuotationId:_this.formInline.requestForQuotationId,auditorExplain:_this.reviewForm.textarea,auditorTime:auditorTime,auditorStatus:auditorStatus};
                $.ajax({
                    url:_this.procurement_service+'inquiryAuditor/update',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            var success=_this.languageType=="zh"?'审核成功！':'Audit success!';
                            _this.common.successTip(success);
                            _this.$router.push("/InquirySheet");
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 审批按钮
            handleApprove(){
                var _this=this;
                _this.handleApprovalVisible=true;
            },
            examinationAndApproval(approverStatus){ //1 审批通过  0审批不通过
                var _this = this;
                var approverTime=_this.getTime();
                var tmp = {requestForQuotationId:_this.formInline.requestForQuotationId,approverExplain:_this.approvalForm.textarea,approverTime:approverTime,approverStatus:approverStatus};
                $.ajax({
                    url:_this.procurement_service+'inquiryApprover/update',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            var success=_this.languageType=="zh"?'审批成功！':'Successful approval!';
                            _this.common.successTip(success);
                            _this.$router.push("/InquirySheet");
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            


            // // ===================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: this.nowLangue.success,
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: this.nowLangue.error,
            //         message: p
            //     });
            // }

        }
    }
</script>
